#include <iostream>
#include <string>
#include <vector>
using namespace std;
string LCS(string s1, string s2) 
{
    // write code here
    int m = s1.length();
    int n = s2.length();

    if (m == 0 || n == 0)
        return "-1";

    vector<vector<string>> dp(2, vector<string>(n + 1, ""));
    int row = 1;
    for (int i = 1; i <= m; i++)
    {
        row = 1 - row;
        for (int j = 1; j <= n; j++)
        {
            if (s1[i - 1] == s2[j - 1])
                dp[row][j] = dp[1 - row][j - 1] + s1[i - 1];
            else
            {
                if (dp[row][j - 1].length() >= dp[1 - row][j].length())
                    dp[row][j] = dp[row][j - 1];
                else
                    dp[row][j] = dp[1 - row][j];
            }
        }
    }

    return dp[row][n] == "" ? "-1" : dp[row][n];
}